<?php 
/* This is the skeleton of all functions and procedures
 * 
 */
session_start();

require_once 'config/config.php';
require_once 'config/var.php';

//connect to mysql database
$sql_connection = mysql_connect(db_host,db_user,db_pass);
if (!$sql_connection){ die('Could not connect: ' . mysql_error());}
if (!mysql_select_db(db_name,$sql_connection)){die('Could not select database ' . db_name);}

require_once 'database.php';

//recieved page request
if(isset($_GET['page'])){
	$page = $_GET['page'];
}

if (!(isset($page) && $page!=null)){
	$page=page_home; //redirect to homepage if request is blank
}

//load chat module
require_once 'chat.php';

//handles user profile related procedures
//veries user
require_once 'authorization.php';

if (isset($user) && $user!=null){
	//allow access to modules only if a user is signed in.
	require_once 'game.php';
	require_once 'leaderboard.php';
	
	//save session
	$_SESSION['user']=$user;
} else {
	$_SESSION['user']=null;
}

//one time setup for some settings of database
//it is safe to be commented out after the first run;
require_once 'setup.php';

//distinguish ajax requests.
//for ajax requests, don't draw a new page
//all ajax requests set $page='ajax' after processing in the modules above
if (isset($page)){
	if($page==page_home){
		$submit_msg='User database has been reset. As much as we would like not to say this but please register another time xD';
	}
	if($page!=page_ajax){
		include_once 'pages.php';
	}
}



mysql_close($sql_connection);
?>